
var product;
var comment;
var orderNo;
var satisfaction=5;
apiready = function(){

    //点击评分
    var lnav = $api.domAll(".satisfaction");  
    for(var i in lnav){
        $api.addEvt(lnav[i], 'click', function(){
             
             var fen=$api.attr(this, 'val');
             satisfaction=fen;
             for (var i = 0; i <lnav.length; i++) {
                 if(i<fen){
                    $api.removeCls(lnav[i], 'unchecked');
                 }else{
                    $api.addCls(lnav[i], 'unchecked');
                 }
			 }
            
        });
        
    }

    orderNo=api.pageParam.orderNo;
	product=api.pageParam.product;
	comment=api.pageParam.comment;
	
	$api.attr($api.byId('proimg'), 'src', serviceUrl+product.proDefImg);
	$api.text($api.byId('proname'), product.proName);
	
	if(product.iscomment=='否'){
	    $api.css($api.byId('commentbut'),'display:block');
	}
	
	
	if(comment.length>0){
	   var ahtml='';
	   for(var i=0;i<comment.length;i++){
	       ahtml+='<div class="am-u-sm-12" style="padding: 0px">';
		       ahtml+='<div class="am-u-sm-12" style="padding:0px;margin-top:5px;">';
			       ahtml+='<div class="am-u-sm-4" >';
			       for(var j=0;j<comment[i].satisfaction;j++){
			          ahtml+='<i class="am-icon-star" style="color: #fc7d0d"></i>';
			       }
			       ahtml+='</div>';
			       ahtml+='<div class="am-u-sm-8" style="font-size:14px;text-align:right">';
			       ahtml+=comment[i].nickName+'&nbsp;'+comment[i].commentTime;
			       ahtml+='</div>';
		       ahtml+='</div>';
		       ahtml+='<div class="am-u-sm-12">';
		       ahtml+=comment[i].content;
		       ahtml+='</div>';
	       ahtml+='</div>';
	       
	   }
	   
	   $api.html($api.byId('commentlist'), ahtml);
	
	}
	
};


//提交
function addpingjia(){
   var check=$api.val($api.dom('input[id="niming"]:checked'));
   var name;
   if(check){
       name=check;
   }else{
       name=$api.getStorage('member2').nickName?$api.getStorage('member2').nickName:$api.getStorage('member2').account;
   }
   
 
   
   var content=$api.byId('content').value;
   if($api.trim(content).length<5){
       toast('内容太短啦!');
	   return;
   }
   
   var data={
       'account':$api.getStorage('account'),
       'src':api.deviceName,
       'content':content,
       'nickName':name,
       'satisfaction':satisfaction,
       'proId':product.id,
       'orderNo':orderNo,
   };
   
   //alert(JSON.stringify(data))
   //return;
   
   do_ajax("/app/member/pjsubmit",'post',data,function(result,err){
		api.hideProgress();
		if(result.resultCode == '0') {
		    
		    api.sendEvent({
			    name: 'procomment',
			    extra: result.order.item                              
			});
		    toast('感谢评价!');
		    //发送评论事件
		
		    setTimeout(function () {
 			   // openWin('commentpro',{'order':result.order});
 			    api.closeWin();
            }, 2000);
		   
		}else{
		   toast(result.datas);
		}
				
	});
   
   
   

};

